home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / GAMES / WIMPGAME / MINES2.ZIP / !Mines / c / HintATest < prev    next >
Text File  |  1995-02-03  |  4KB  |  128 lines

  1. /* Testrahmen f"ur die Asseblerprozedur
  2. ** test_if_possible
  3. */
  4. typedef struct {char x,y,domain;int test;} border_typ;
  5.  
  6. #include <stdio.h>
  7. #include "HintA.h"
  8.  
  9. #define FALSE 0
  10. #define TRUE 1
  11.  
  12. #define XMAX 30
  13. #define YMAX 16
  14.  
  15. int feld[XMAX][YMAX];
  16. border_typ b;
  17.  
  18. #define MINE 1
  19. #define MARK 2
  20. #define CLOSED 4
  21.  
  22. int off[8][2] = { {-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{-1,1},{0,1},{1,1}};
  23.  
  24. #define in_playground(x,y) (((x)>=0) && ((x)<XMAX) && ((y)>=0) && ((y)<YMAX))
  25.  
  26. int c_test_if_possible(border_typ *border_ptr)
  27. {
  28.     /* Testet, ob die Wahl dieses Feldes gegen Informationen
  29.        der Nachbarfelder verstoesst */
  30.     char d0,d1,mines,marks,x1,y1;
  31.     for (d0=0;d0<8;d0++)
  32.     {
  33.         x1=border_ptr->x+off[d0][0];
  34.         y1=border_ptr->y+off[d0][1];
  35.         if (in_playground(x1,y1) && !(feld[x1][y1] & CLOSED))
  36.         {
  37.             mines=0;marks=0;
  38.             for (d1=0;d1<8;d1++)
  39.             {
  40.                 char x2=x1+off[d1][0],y2=y1+off[d1][1];
  41.                 if (in_playground(x2,y2))
  42.                 {
  43.                     register char f=feld[x2][y2];
  44.                     if (f & MINE) mines++;
  45.                     if (f & MARK) marks++;
  46.                 }
  47.             }
  48.             if ((border_ptr->test & (1 << d0))!=0)
  49.                  { if (marks>mines) return FALSE; }
  50.             else { if (marks!=mines) return FALSE; }
  51.         }
  52.     }
  53.     return(TRUE);
  54. }
  55.  
  56. void do_tip(void)
  57. {
  58.   FILE *f;
  59.   int x,y;
  60.   if ((f=fopen("<Mines$Dir>.tip","rb"))==0) return;
  61.   while (!feof(f)) {
  62.       fread(&b,4,sizeof(char),f);
  63.       for (x=-2;x<=2;x++) for (y=-2;y<=2;y++)
  64.         if (in_playground(b.x+x,b.y+y)) fread(&(feld[b.x+x][b.y+y]),1,sizeof(int),f);
  65.       for (y=-2;y<=2;y++)
  66.       {
  67.         for (x=-2;x<=2;x++) if (in_playground(b.x+x,b.y+y)) printf("%3x",feld[b.x+x][b.y+y]); else printf(" . ");
  68.         printf("\n");
  69.       }
  70.       if (c_test_if_possible(&b)) printf("TRUE "); else printf("FALSE ");
  71.       if (test_if_possible(&b,XMAX,YMAX,(char *)feld)) printf("TRUE\n"); else printf("FALSE\n");
  72.   }
  73.   fclose(f);
  74. }
  75.  
  76. void brute_force(void)
  77. {
  78.   int x0,y0,d0,and,or,m,d1,i;
  79.   int x[25]={2,2,2,1,3,1,1,3,3,0,0,0,0,0,1,1,2,2,3,3,4,4,4,4,4},
  80.       y[25]={2,1,3,2,2,1,3,1,3,0,1,2,3,4,0,4,0,4,0,4,0,1,2,3,4},
  81.       fx[5]={0,1,15,28,29},fy[5]={0,1,8,14,15},
  82.       prev[8]={0,0,1,5,2,6,7,4};
  83.   for (i=0;i<25;i++)
  84.   {
  85.     printf("%i ",i);
  86.     x0=fx[x[i]];y0=fy[y[i]];
  87.     b.x=x0;b.y=y0;b.test=0;
  88.     for (d0=0;d0<8;d0++)
  89.     {
  90.       int x1=x0+off[d0][0],y1=y0+off[d0][1],
  91.           x2=x0+off[prev[d0]][0],y2=y0+off[prev[d0]][1];
  92.       if (!in_playground(x1,y1) || !in_playground(x2,y2)) continue;
  93.       feld[x1][y1]&=~CLOSED;feld[x2][y2]&=~CLOSED;
  94.       and=0xFFFF;or=0;
  95.       for (m=0;m<65536;m++)
  96.       {
  97.         for (d1=0;d1<8;d1++)
  98.         {
  99.           int x2=x1+off[d1][0],y2=y1+off[d1][1];
  100.           if (in_playground(x2,y2) && (!(feld[x2][y2] & CLOSED)))
  101.           {
  102.             if (m & (1 << d1)) feld[x2][y2]|=MINE;
  103.                     else feld[x2][y2]&=~MINE;
  104.             if (m & (1 << (d1+8))) feld[x2][y2]|=MARK;
  105.                     else feld[x2][y2]&=~MARK;
  106.           }
  107.         }
  108.         if (c_test_if_possible(&b)!=test_if_possible(&b,XMAX,YMAX,feld))
  109.             { and&=m;or|=m;}
  110.       }
  111.       feld[x1][y1]|=CLOSED;feld[x2][y2]|=CLOSED;
  112.       if ((and!=0xFFFF) || (or!=0))
  113.       {
  114.         printf("x:%i y:%i d0:%i and: %4x or: %4x\n",x0,y0,d0,and,or);
  115.       }
  116.     }
  117.     printf("\n");
  118.   }
  119. }
  120.  
  121. int main(void)
  122. {
  123.   border_typ b;
  124.   /*brute_force();*/
  125.   printf("%i %i",sizeof(border_typ),(char *)&b.test - (char *)&b);
  126.   return 0;
  127. }
  128.